local assets = {
    -- Asset("IMAGE", "images/inventoryimages/spell_reject_the_npc.tex"),
	-- Asset("ATLAS", "images/inventoryimages/spell_reject_the_npc.xml"),
	Asset("ANIM", "anim/npc_fx_trade_bubble.zip"),
}


local function fx()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    inst:AddTag("INLIMBO")
    inst:AddTag("FX")
    inst:AddTag("NOBLOCK")
    -- inst:DoTaskInTime(5,inst.Remove)
    -- FX:ListenForEvent("animqueueover",FX.Remove)
    -- FX:ListenForEvent("animoever",FX.Remove)

    inst.AnimState:SetBuild("npc_fx_trade_bubble")
    inst.AnimState:SetBank("npc_fx_trade_bubble")
    inst.AnimState:PlayAnimation("idle",true)
    inst.AnimState:SetScale(1.3,1.3,1.3)

    ---------------------------------------------------    

    -- inst:AddComponent("talker")
    -- inst.components.talker.offset = Vector3(60, -160, 0)
    -- inst.components.talker.colour = Vector3(255/255 , 255/255 , 255/255)  --- RGB

    if not TheWorld.ismastersim then
        return inst
    end


    inst:ListenForEvent("Show",function(inst,_table)
        -- _table = {
        --     wanted_image = "moonrockseed" , -- prefab name
        --     wanted_num = 10,        0~99
        --     ret_image = "log",
        --     ret_num = 1,
        --     pause = nil
        -- }
        if _table and  _table.wanted_image and _table.wanted_num and _table.ret_image and _table.ret_num then
            inst.Ready = true
            
            local wanted_image = _table.wanted_image
            local wanted_num = _table.wanted_num
            local ret_image = _table.ret_image
            local ret_num = _table.ret_num

            if wanted_num < 10 then
                inst.AnimState:HideSymbol("W_NUM_HIGH")
                inst.AnimState:HideSymbol("W_NUM_LOW")
                inst.AnimState:ShowSymbol("W_NUM_MID")
            else
                inst.AnimState:ShowSymbol("W_NUM_HIGH")
                inst.AnimState:ShowSymbol("W_NUM_LOW")
                inst.AnimState:HideSymbol("W_NUM_MID")
            end

            if ret_num < 10 then
                inst.AnimState:HideSymbol("R_NUM_HIGH")
                inst.AnimState:HideSymbol("R_NUM_LOW")
                inst.AnimState:ShowSymbol("R_NUM_MID")
            else
                inst.AnimState:ShowSymbol("R_NUM_HIGH")
                inst.AnimState:ShowSymbol("R_NUM_LOW")
                inst.AnimState:HideSymbol("R_NUM_MID")
            end
            if wanted_image == "npc_item_goldnugget_coin" then
                inst.AnimState:OverrideSymbol("WANTED_SWAP_SIGN", "npc_fx_trade_bubble","coin1")
            else                
                inst.AnimState:OverrideSymbol("WANTED_SWAP_SIGN", GetInventoryItemAtlas(wanted_image..".tex"), wanted_image..".tex")
            end

            inst.AnimState:OverrideSymbol("RET_SWAP_SIGN", GetInventoryItemAtlas(ret_image..".tex"), ret_image..".tex")

            local w_num_high = math.floor(wanted_num/10)
            local w_num_low = math.floor(wanted_num%10)

            inst.AnimState:OverrideSymbol("W_NUM_HIGH", "npc_fx_chat_bubble", tostring(w_num_high))
            inst.AnimState:OverrideSymbol("W_NUM_LOW", "npc_fx_chat_bubble", tostring(w_num_low))
            inst.AnimState:OverrideSymbol("W_NUM_MID", "npc_fx_chat_bubble", tostring(w_num_low))


            local r_num_high = math.floor(ret_num/10)
            local r_num_low = math.floor(ret_num%10)

            inst.AnimState:OverrideSymbol("R_NUM_HIGH", "npc_fx_chat_bubble", tostring(r_num_high))
            inst.AnimState:OverrideSymbol("R_NUM_LOW", "npc_fx_chat_bubble", tostring(r_num_low))
            inst.AnimState:OverrideSymbol("R_NUM_MID", "npc_fx_chat_bubble", tostring(r_num_low))
        end

    end)


    inst:DoTaskInTime(0.1,function()
        if inst.Ready ~= true then
            inst:Remove()
        end
    end)



    return inst
end

return Prefab("npc_fx_trade_bubble",fx,assets)